package day2.HomeWork;

/**
 * ClassName：Test13
 *
 * @Author：小鱼
 * @Create：2025-08-19 18:28
 */
public class Test13 {
    //编写程序，实现创建一个线程，并调用方法实现输出这个线程状态所经历的NEW、RUNNABLE、TIMED_WAITING和TERMINATED状态
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(){
            @Override
            public void run(){
                try {
                    // 子线程休眠1秒，这段时间会处于TIMED_WAITING状态
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        //线程启动前，预计 NEW
        System.out.println(thread.getState());
        System.out.println(thread.getState());
        //启动线程
        thread.start();
        // RUNNABLE
        System.out.println(thread.getState());
        System.out.println(thread.getState());

        Thread.sleep(300);
        //此处：子线程依旧 sleep TIMED_WAITING
        System.out.println(thread.getState());
        System.out.println(thread.getState());

        Thread.sleep(1000);
        //预计输出：终止状态
        System.out.println(thread.getState());
        System.out.println(thread.getState());

    }
}
